package com.openspring.framework.dao;

import java.io.Serializable;
import com.openspring.framework.util.GenericUtils;

/**
 * 抽象的泛型DAO, 作为统一解析实体和主键的class对象
 * @author HeBin
 *
 * @param <T> 实体
 * @param <ID> 主键
 */
public abstract class AbstractGenericDAO<T, ID extends Serializable> implements GenericDAO<T, ID> {

	private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(AbstractGenericDAO.class);
	private Class<T> persistentClass;
	private Class<ID> primaryKeyClass;
	
	public Class<T> getPersistentClass() {
		return persistentClass;
	}
	public Class<ID> getKeyClass() {
		return primaryKeyClass;
	}

	@SuppressWarnings("unchecked")
	public AbstractGenericDAO() {
	    persistentClass = (Class<T>) GenericUtils.getGenericSuperArgumentsclass(getClass());
	    primaryKeyClass = (Class<ID>) GenericUtils.getGenericSuperArgumentsclass(getClass(), 1);
	    if(logger.isDebugEnabled())
	    	logger.debug("T : " + persistentClass.toString() + ", ID : " + primaryKeyClass.toString());
	}
}
